<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>w_custom_columns基本信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/forms/currencyCss.css">
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<form class="layui-form qbdms-bodyDiv"  requrl="{{serverPath.qbdmsPath}}/qbdms/wCustomColumns/get" lay-filter="wCustomColumnsDataForm">
    <div id="content" class="layui-row">
    </div>
    <div class="layui-form-item" style="position: fixed;bottom: 31px;left: 0;margin-bottom: 0;width: 100%;">
        <div style="text-align: center;">
            <a lay-submit lay-filter="wCustomColumns" class="layui-btn btn-n privateSubmit qbdms-oneBtn">提交</a>
            <button type="reset" id="closeWindow" style="margin-left: 10px;" class="layui-btn btn-n layui-btn-danger btn-save qbdms-oneBtnLine">取消</button>
        </div>
    </div>
</form>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script id="demo" type="text/html">
            <div class="qbdms-oneForm">
                <label class="layui-form-label qbdms-label" title="{{d.title}}">{{d.title}}<span style="color: red;">*</span></label>
                <span style="float: right;line-height: 40px">%</span>
                <div class="layui-input-block qbdms-input" style="margin-right: 20px">
                    <input type="text" placeholder="请输入" autocomplete="off"
                           class="layui-input filter-value" name="{{d.field}}" value="{{ d.width?(d.width.toString().indexOf('%')!=-1?d.width.toString().split('%')[0]:d.width):0 }}"
                           lay-verify="required|positiveInteger"
                            maxlength="40">
                </div>
            </div>
</script>
<script>
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','common','jquery',"publicMethods",'laytpl','qbdmsForm'], function () {
        var $ = layui.jquery;
        var common = layui.common;
        var laytpl = layui.laytpl;
        var form = layui.qbdmsForm;
        var publicMethods = layui.publicMethods;
        //关闭当前页面
        $("#closeWindow").click(function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        });
        var id = '${id}';
        var fieldJson;
        var isDefault;
        $.ajax({
            url: serverPath.qbdmsPath + "/qbdms/wCustomColumns/get",
            dataType: 'json',
            data: {id:id},
            success: function (data) {
                if (common.filterRecord(data)) {
                    var ret = data.data;
                    if(ret){
                        fieldJson = JSON.parse(ret.fieldJson,function(k,v){
                            if(v.indexOf && v.indexOf('function') > -1){
                                return eval("(function(){return "+v+" })()")
                            }
                            return v;
                        });
                        isDefault = ret.isDefault;
                        var prefix = '<div class="layui-form-item">';
                        var prefix1 = '<div class="layui-inline">';
                        var prefix2 = '<div class="layui-input-inline">';
                        var suffix = '</div>';
                        var htm = "";
                        $.each(fieldJson,function(i,n){
                            var field = n.field;
                            var hide = n.hide;
                            if(!field || field == 'sn' || hide == 'true' || hide == true){
                                return true;
                            }
                            var data = n;
                            var getTpl = demo.innerHTML
                                ,view = document.getElementById('content');
                            laytpl(getTpl).render(data, function(html){
                                view.innerHTML += html;
                            });


//                            var width = n.width;
//                            width = width?(width.toString().indexOf("%")!=-1?width.toString().split("%")[0]:width):0;

//                            htm += prefix;
//                            htm += prefix1;
//                            htm += '<label title="'+n.title+'" class="layui-form-label">'+n.title+'</label>';
//                            htm += prefix2;
//                            htm += '<input type="text" class="layui-input filter-value" name="'+field+'" value="'+width+'" lay-verify="required|positiveInteger"/><span style="margin-left: 10px;">%</span>';
//                            htm += suffix;
//                            htm += suffix;
//                            htm += suffix;
                        });
//                        $("#content").html(htm);
                    }
                } else {
                    layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                }
            }
        });

        form.verify(publicMethods.formVerify);
        //监听提交
        form.on('submit(wCustomColumns)', function (data) {
            if(fieldJson){
                $.each(data.field,function(i,n){
                    $.each(fieldJson,function(ii,nn){
                      if(i == nn.field){
                          nn.width = n+"%";
                          return false;
                      }
                    });
                });
                $.each(fieldJson,function(ii,nn){
                    if (typeof nn.templet === 'function') {
                        nn.templet = ((nn.templet + '').replace(/[\n]/g,""));
                    }
                });
                data.field = {};
                data.field.id = id;
                data.field.fieldJson = fieldJson;
                $.ajax({
                    url: serverPath.qbdmsPath + "/qbdms/wCustomColumns/save",
                    type: "POST",
                    contentType: 'application/json',
                    dataType: 'json',
                    data: JSON.stringify(data.field),
                    success: function (data) {
                        if (common.filterRecord(data)) {
                            layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'}, function (index) {
                                if(isDefault == '1'){
                                    parent.parent.tableInstace(JSON.stringify(fieldJson));
                                }
                                layer.close(index);
                                parent.layui.table.reload('wCustomColumnsTable');
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        } else {
                            layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                        }
                    }
                });
            }
        });
    });
</script>
<style>
    body{
        padding: 16px;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        -o-box-sizing: border-box;
        -ms-box-sizing: border-box;
        box-sizing: border-box;
    }
    form.qbdms-bodyDiv{
        background: #fff;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        -o-box-sizing: border-box;
        -ms-box-sizing: border-box;
        box-sizing: border-box;
        height: 100%;
    }
    .qbdms-oneForm{
        width: 50%;
    }
    #content{
        height: 87%;
        overflow: auto;
    }
</style>
</body>
</html>